package cn.quevo.cube.api.data;

import cn.quevo.common.annotation.RequiresPermissions;
import cn.quevo.common.entity.ResultEntity;
import cn.quevo.common.enums.ResultStatusEnum;
import cn.quevo.common.lang.StringUtils;
import cn.quevo.core.spring.SpringController;
import cn.quevo.cube.provide.data.entity.CubeModelDataClob;
import cn.quevo.cube.provide.data.entity.query.CubeModelDataClobQuery;
import cn.quevo.cube.provide.data.service.CubeModelDataClobService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 大文本数据记录 RestController
 *
 * @author July july_sky@foxmail.com
 * @version 1.0
 * @date 2018/12/11 14:57:55
 * @Copyright 湘豫（北京）科技有限公司版权所有.All Rights Reserved.
 */
@RestController("cubeModelDataClobController")
@RequestMapping("/cube/")
public class CubeModelDataClobRestController extends SpringController{

    @Resource(name="cubeModelDataClobService")
    private CubeModelDataClobService cubeModelDataClobService;

    /**
     * 分页加载大文本数据记录
     *
     * @param cubeModelDataClobQuery
     * @return
     * @author July july_sky@foxmail.com
     * @date 2018/12/11 14:57:55
     */
    @RequestMapping(value="cubeModelDataClob",method= RequestMethod.GET)
    @RequiresPermissions("cube:cubeModelDataClob:list")
    public ResultEntity page(CubeModelDataClobQuery cubeModelDataClobQuery){
        return cubeModelDataClobService.getPage(cubeModelDataClobQuery);
    }

    /**
     * 保存大文本数据记录
     *
     * @param cubeModelDataClob
     * @return
     * @author July july_sky@foxmail.com
     * @date 2018/12/11 14:57:55
     */
    @RequestMapping(value="cubeModelDataClob",method=RequestMethod.POST)
    @RequiresPermissions("cube:cubeModelDataClob:create")
    public ResultEntity create(CubeModelDataClob cubeModelDataClob){
        if(cubeModelDataClobService.create(cubeModelDataClob) <= 0){
            return new ResultEntity(ResultStatusEnum.RECORD_REPEAT);
        }
        return ResultEntity.success();
    }

    /**
     * 修改大文本数据记录
     *
     * @param cubeModelDataClob
     * @param id
     * @return
     * @author July july_sky@foxmail.com
     * @date 2018/12/11 14:57:55
     */
    @RequestMapping(value="cubeModelDataClob//{id:\\d+}",method=RequestMethod.PUT)
    @RequiresPermissions("cube:cubeModelDataClob:update")
    public ResultEntity update(CubeModelDataClob cubeModelDataClob, @PathVariable("id") Long id){
        if (StringUtils.isBlank(id)) {
            return ResultEntity.fail(ResultStatusEnum.RECORD_UNSELECTED);
        }
        cubeModelDataClob.setId(id);
        if (StringUtils.isBlank(this.cubeModelDataClobService.update(cubeModelDataClob))) {
            return ResultEntity.fail(ResultStatusEnum.RECORD_REPEAT);
        }
        return ResultEntity.success();
    }
}
